The FIFA 21 dataset is a comprehensive collection of data related to football players, teams, and matches from the FIFA 21 video game. It includes detailed information such as player attributes, team statistics, and match outcomes. The dataset spans from the game’s release in 2020 . This dataset was obtained from Kaggle.
A preliminary analysis of the FIFA 21 dataset reveals several errors and inconsistencies that need to be addressed. These issues can be corrected using string manipulation techniques along with other data cleaning methods. By cleaning the dataset, we can ensure accurate and reliable data for further analysis and insights.
Libraries Used
The tidyverse library is a collection of R packages that can be used in Data Analysis. Some of the packages to be used are the readr for data import, dplyr for data wrangling, stringr for string manipulation to mention a few. Since these packages are housed and are core packages in the tidyverse. I call this library since it is already installed.
#load libraries library(knitr)library(lubridate)
Attaching package: 'lubridate'
The following objects are masked from 'package:base':
date, intersect, setdiff, union
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(kableExtra)
Attaching package: 'kableExtra'
The following object is masked from 'package:dplyr':
group_rows
Note
Should it not be installed, run the code block below before calling the libraries for use.
The kableExtra package in R is designed to enhance the functionality of tables
Data Import
The FIFA 21 dataset is a CSV file from Kaggle. To dive deep into the data, I proceeded to import it into RStudio, the IDE for the R Programming Language but not without first setting working directory.
Setting Working Directory
setwd("C:/Users/SAMMY/Desktop/FIFA21")
Reading in Data
#read in fifa 21 csvfifa21raw<-read_csv("fifa21 raw data v2.csv")
Rows: 18979 Columns: 77
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (23): Name, LongName, photoUrl, playerUrl, Nationality, Club, Contract, ...
dbl (54): ID, Age, ↓OVA, POT, BOV, Attacking, Crossing, Finishing, Heading A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
A peek into the dataset just to get familiar with what the data is about :
Upon examining the dataframe, some column names are inconsistent and badly formatted, hence the need to rename
#renamed ColumnNames for easy readabilityfifa21raw<-fifa21raw %>%rename(Overall_Analysis=`↓OVA`,PlayerPotential=POT,Best_Overall=BOV,Joined_National=Joined,Skill_Moves=SM,AttackingWorkRate=`A/W`,DefensiveWorkRate=`D/W`,WeakFootRating=`W/F`,InjuryRating=IR,Shooting=SHO,Pace=PAC,Weight_kg=Weight)
The purpose of this codeblock above is to make the column names in the fifa21raw dataframe more descriptive and easier to understand. This helps improve readability of code, especially when working with the data frame in subsequent analyses or visualizations.
Data Dictionary
Here is the data dictionary describing the columns in the dataframe.
check
To crosscheck the rename() is effected in dataframe
The Club column contains clubs of respective players and upon examining the column, it is populated with nextline characters “\n” which leaves the Club column in bad format.
#Removed nextline characters found in the club columnfifa21raw<-fifa21raw %>%mutate(Club=str_remove_all(Club,"\n"))
The code chunk above rids the Club column of any nextline characters by use of the str_remove_all()
check
To crosscheck that the column is clear of any nextline characters:
fifa21raw %>%select(Club) %>%head(10)
# A tibble: 10 × 1
Club
<chr>
1 FC Barcelona
2 Juventus
3 Atlético Madrid
4 Manchester City
5 Paris Saint-Germain
6 FC Bayern München
7 Liverpool
8 Liverpool
9 Paris Saint-Germain
10 FC Barcelona
Contract Column
The Contract column contains information about the duration of contracts and loan periods for players.
This code chunk above separates the Contract column into start_year and end_year, classifies contracts as ‘Free’, ‘Loan’, or ‘Full-Time’, handles missing values for start_year and end_year based on contract type, and converts these columns to numeric values for further analysis.
check
To crosscheck that the new columns are created off the existing column to determine what groups are the players’ Contract_type and all changes effected:
This function helps to convert and standardize height values ~ some in feet and inches, and others in centimeters for the purpose of consistency and data quality
check
To crosscheck that the height column has been standardized
This function helps to convert and standardize weight values ~ some in pounds, kilogram and others in centimeters for the purpose of consistency and data quality
check
To crosscheck that the weight column has been standardized
The Value, Wage and Release Clause columns house the worth of a player in the market, their earnings in their clubs and the fee to be paid to release a player from their contract respectively.
Upon close examination, the columns are of character datatype and contain the Euro currency symbol (€). Additionally, they use “M” to represent values in millions and “K” to represent values in thousands.
This code chunk above processes the value, wage, and release clause columns by removing currency symbols and suffixes, removing non-numeric characters and converting to numeric values.
check
To crosscheck that the columns have been appropriately processed (cleaned of currency, millions and thousands symbols and converted to numeric values):
The Weak Foot, Skill Moves, and Injury Rating columns collectively provide insights into a player’s technical skills and physical resilience. The Weak Foot rating (1 to 5 stars) shows proficiency with the non-dominant foot, enhancing versatility. The Skill Moves rating (1 to 5 stars) reflects the ability to perform complex dribbles. The Injury Rating (1 to 5 stars) indicates susceptibility to injuries, with lower ratings suggesting better durability.
A peek at some of the observations in these columns is as below:
In this project, the FIFA 21 dataset was successfully wrangled by cleaning, transforming, and structuring the data. This process ensured the dataset was accurate, consistent, and ready for analysis. The cleaned data can now be used for various analytical tasks, providing valuable insights into player performance and team comparisons.